package com.real.operationalcontrols.工具包;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.amap.api.maps.model.LatLng;
import com.blankj.utilcode.util.AppUtils;
import com.real.operationalcontrols.R;

import java.math.BigDecimal;

public class NumberUtils {

    public static boolean isNumeric(String str) {
        String bigStr;
        try {
            bigStr = new BigDecimal(str).toString();
        } catch (Exception e) {
            return false;//异常 说明包含非数字。
        }
        return true;
    }

    public static void toGaodeDaohang(LatLng latLng, String name, Context context) {

        if (AppUtils.isInstallApp("com.autonavi.minimap")) {// 是否安装了高德
            Intent intents = new Intent();
            intents.setData(Uri.parse("androidamap://navi?sourceApplication=运维管控&poiname=" + name + "&lat=" + latLng.latitude + "&lon=" + latLng.longitude + "&dev=0&style=2"));
            context.startActivity(intents); // 启动调用
        } else {
            try {
                Uri uri = Uri.parse("http://uri.amap.com/marker?position=" + latLng.longitude + ","
                        + latLng.latitude +
                        "&name=" + name + "&src=com.real.operationalcontrols&coordinate=gaode" +
                        "&callnative=0");
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.addCategory(Intent.CATEGORY_DEFAULT);
                context.startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static int getAqiColor(String value) {
        boolean isNumber = isNumeric(value);
        if (isNumber) {
            double b = Double.parseDouble(value);
            if (b <= 50) {
                return R.color.aqi_one;
            } else if (b <= 100 && b > 50) {
                return R.color.aqi_two;
            } else if (b <= 150 && b > 100) {
                return R.color.aqi_three;
            } else if (b <= 200 && b > 150) {
                return R.color.aqi_four;
            } else if (b <= 300 && b > 200) {
                return R.color.aqi_five;
            } else if (b > 300) {
                return R.color.aqi_six;
            }
        } else {
            return R.color.aqi_one;
        }
        return R.color.aqi_one;
    }
}
